<?php

namespace app\service\role;

use app\model\Role as RoleModel;
use think\Db;

class RoleService implements IRoleService
{
    /**
     * 获取角色列表
     * @param $queryString
     * @param $pageSize
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getRoleList($queryString, $pageSize)
    {
        $roleModel = new RoleModel();
        $page_param = ['query' => []];
        if(!empty($queryString)) {
            $page_param['query']['queryString'] = $queryString;
            $keyWord = '%' . $queryString . '%';
            $roleModel->where('role_name', 'like', $keyWord);
        }
        $list = $roleModel->where('role_status', '<>', -1)
            ->paginate($pageSize, false, $page_param);
        return $list;
    }

    /**
     * 检查角色是否存在
     * @param $name
     * @return array|null|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function checkRoleIsExist($name) {
        $role = Db::table('aya_role')
            ->where('role_name', '=', $name)
            ->where('role_status', '<>', -1)
        ->find();
        return $role;
    }
}